<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/13
 * Time: 17:06
 */
namespace common\components\widgets;

use yii\base\Widget;

class Datetimepicker extends Widget{

    public $format;

    public $formatTime;

    public $formatDate;

    public $timepicker;

    public $datepicker;

    public $todayButton;

    public $step;


    public $flag;

    public function init(){
        parent::init();
        if ($this->format === null) {
            $this->format='Y/m/d';
        }
        if ($this->formatTime === null) {
            $this->formatTime='H:i';
        }
        if ($this->formatDate === null) {
            $this->formatDate= 'Y/m/d';
        }
        if ($this->timepicker === null) {
            $this->timepicker= 'false';
        }
        if ($this->datepicker === null) {
            $this->datepicker= 'true';
        }
        if ($this->todayButton === null) {
            $this->todayButton='false';
        }
        if ($this->step === null) {
            $this->step=60;
        }
        if ($this->flag === null) {
            $this->flag='datetimepicker';
        }
    }
    public  function run(){
        $view = $this->getView();
        $js=<<<JS
        $.datetimepicker.setLocale("ch");
        $(".$this->flag").datetimepicker({
            format:"$this->format",
            formatTime:"$this->formatTime",
            formatDate:"$this->formatDate",
            timepicker:$this->timepicker,
            todayButton:$this->todayButton,
            step:$this->step,
            datepicker:$this->datepicker
});
JS;
        $view->registerJs($js);

    }
}
